<template>
  <zcb-dialog v-model="dialogTableVisible" :title="title" showClose>
    <!-- 开评标规则 -->
    <template v-if="params.code === 'tenderEvaluationRule'">
      <el-form label-position="left" label-width="auto">
        <el-form-item :label="t('keys.Bid_opening_format')">
          {{
            params.detailsInfo?.tenderOpenSequence === 'SINGLE_STEP'
              ? t('keys.One_step_bid_opening')
              : params.detailsInfo?.tenderOpenSequence === 'SUB_STEP'
              ? t('keys.Stepwise_bid_opening')
              : '--'
          }}
        </el-form-item>
        <el-form-item :label="t('keys.Simultaneous_evaluation_of_bids')" v-if="params.detailsInfo?.tenderOpenSequence == 'SINGLE_STEP'">
          {{
            params.detailsInfo?.tenderTogetherEvaluation === 'TRUE'
              ? t('keys.yes')
              : params.detailsInfo?.tenderTogetherEvaluation === 'FALSE'
              ? t('keys.no')
              : '--'
          }}
        </el-form-item>
        <el-form-item :label="t('keys.bid_opening_and_evaluation_rules_information')">
          <span style="margin-right: 10px">
            {{ params.detailsInfo?.evaluationBidRuleReq?.ruleName }}
            {{ params.detailsInfo?.evaluationBidRuleReq?.remark ? '-- ' + params.detailsInfo?.evaluationBidRuleReq?.remark : '' }}
          </span>
        </el-form-item>
      </el-form>
      <row-table-v1
        :column="tenderEvaluationRuleColumn"
        :tableData="params.detailsInfo?.tenderEvaluationRule"
        :showActionBtn="false"
        :showIndex="false"
      >
        <template #typeDesc="{ scope }">
          <span class="sort">
            <span>{{ scope.typeDesc }}</span>
          </span>
        </template>
        <template #selected="{ scope }">
          <el-checkbox v-model="scope.selected" true-label="TRUE" false-label="FALSE" :disabled="true" />
        </template>
        <template #order="{ scope }">
          <span v-if="params.detailsInfo?.tenderTogetherEvaluation == 'TRUE'">--</span>
          <span v-else>{{ scope.order }}</span>
        </template>
      </row-table-v1>
    </template>
    <!-- 关联单据 -->
    <template v-else-if="params.code === 'businessRelation'">
      <row-table-v1 v-loading="loading" :column="businessRelationColumn" :tableData="tableData" :showActionBtn="false"> </row-table-v1>
    </template>
  </zcb-dialog>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useI18n } from 'vue-i18n'
import { getFindBySourcing } from '@/api/personalCenter'
import { ERR_OK } from '@/config/statusCode'
const { t } = useI18n() // 中英文
const params = ref({})
const dialogTableVisible = ref(false)
const title = ref('查看')
const tableData = ref([])
const loading = ref(false)

const businessRelationColumn = ref([
  {
    field: 'businessTypeCn',
    fieldCode: 'businessTypeCn',
    fieldName: t('keys.doc_type'),
    displayFlag: true,
    fieldTypeCode: 'text',
    presetFlag: true,
    width: 100
  },
  {
    field: 'businessCode',
    fieldCode: 'businessCode',
    fieldName: t('keys.docment_code'),
    displayFlag: true,
    fieldTypeCode: 'text',
    presetFlag: true,
    width: 150
  },
  {
    field: 'demandSeqNo',
    fieldCode: 'demandSeqNo',
    fieldName: 'PR行号',
    displayFlag: true,
    fieldTypeCode: 'text',
    presetFlag: true,
    width: 150
  },
  {
    field: 'businessName',
    fieldCode: 'businessName',
    fieldName: t('keys.docment_name'),
    displayFlag: true,
    fieldTypeCode: 'text',
    presetFlag: true,
    width: 150
  },
  {
    field: 'businessStatusCn',
    fieldCode: 'businessStatusCn',
    // fieldName: t('keys.Document_Status'),
    fieldName: t('keys.status'),
    displayFlag: true,
    fieldTypeCode: 'text',
    presetFlag: true
  },
  {
    field: 'businessCreatedByEmpCn',
    fieldCode: 'businessCreatedByEmpCn',
    fieldName: t('keys.createByEmpName'),
    displayFlag: true,
    fieldTypeCode: 'text',
    presetFlag: true
  },
  {
    field: 'businessCreatedTime',
    fieldCode: 'businessCreatedTime',
    fieldName: t('keys.createdTime'),
    displayFlag: true,
    fieldTypeCode: 'text',
    presetFlag: true,
    width: 200
  }
])
const tenderEvaluationRuleColumn = [
  {
    fieldName: t('keys.Bidding_type'),
    field: 'customName',
    fieldCode: 'customName',
    displayFlag: true,
    fieldTypeCode: 'text',
    presetFlag: true
  },
  {
    fieldName: t('keys.Evaluation_Content'),
    field: 'selected',
    fieldCode: 'selected',
    displayFlag: true,
    fieldTypeCode: 'text',
    presetFlag: true
  },
  {
    fieldName: t('keys.Evaluation_sequence'),
    field: 'order',
    fieldCode: 'order',
    displayFlag: true,
    fieldTypeCode: 'text',
    presetFlag: true
  }
]

// 获取接口
const getList = async () => {
  loading.value = true
  const { code, data } = await getFindBySourcing({ sourcingId: params.value?.detailsInfo?.id })
  if (code == ERR_OK) {
    tableData.value = data || []
    loading.value = false
  } else {
    loading.value = false
  }
}

const show = (res) => {
  params.value = res
  console.log(params.value)
  if (params.value.code === 'businessRelation') {
    getList()
  }
  dialogTableVisible.value = true
}
defineExpose({
  show
})
</script>

<style lang="scss" scoped></style>
